import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../views/Layout/Index.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      redirect: '/user',
      meta: {
        title: '主页',
      },
      component: Layout
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login/Login.vue')
    },
    {
      path: '/user',
      name: 'user',
      component: Layout,
      redirect: '/userlist',
      meta: {
        title: '用户管理',
        isMenu: true,
        isAuth: true,
        icon: 'iconfont icon-yonghuguanli1',
      },
      children: [
        {
          path: '/userlist',
          name: 'userlist',
          meta: {
            title: '用户管理',
            isAuth: true,
            icon: 'iconfont icon-yonghuguanli1',
            isMenu: true,
          },
          component: () => import('@/views/user/UserIndex.vue')
        },
        {
          path: '/rolelist',
          name: 'rolelist',
          meta: {
            title: '角色管理',
            isAuth: true,
            icon: 'iconfont icon-jiaosedingyi',
            isMenu: true,
          },
          component: () => import('@/views/role/RoleIndex.vue')
        }
      ]
    },
    {
      path: '/basis',
      name: 'basis',
      component: Layout,
      redirect: '/tagList',
      meta: {
        title: '基础管理',
        isMenu: true,
        isAuth: true,
        icon: 'iconfont icon-caidan',
      },
      children: [
        {
          path: '/tagList',
          name: 'taglist',
          meta: {
            title: '标签管理',
            isAuth: true,
            icon: 'iconfont icon-youhuijuan',
            isMenu: true,
          },
          component: () => import('@/views/Tag/TagIndex.vue')
        },
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'all',
      redirect: '/404',
    },
    {
      path: '/404',
      name: '404',
      component: () => import('@/views/404.vue'),
    }
  ]
})

router.beforeEach((to, from, next) => {
  next()
  // if (!sessionStorage.token) {
  //   if (to.path !== '/login') {
  //     next('/login')
  //     return;
  //   } else {
  //     next();
  //     return
  //   }
  // } else {
  //   next();
  // }
});


export default router
